<?php

namespace App\Http\Controllers\Api\Operate;

use App\Http\Controllers\Controller;
use App\Libs\Strategy\Context;
use App\Models\Operate\Config;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class AppSettingController extends Controller
{
    private $config;

    public function __construct(){
        $this->config = new Context(new Config());
    }

    public function index()
    {
        $configs = $this->config->display(0);

        return $this->success($configs);
    }

    public function store(Request $request)
    {
        if($this->config->create($request->only('type','title','descrition','img','config_type')+['content'=>$request->desc])){
            return $this->success(['message'=>'添加成功']);
        }else{
            return $this->error('添加失败');
        }
    }

    public function update(Request $request,$id)
    {
        if($this->config->update($id,$request->only('type','title','descrition','img','config_type')+['content'=>$request->desc])){
            return $this->success(['message'=>'修改成功']);
        }else{
            return $this->error('修改失败');
        }
    }

    public function show($id)
    {
        return $this->success($this->config->find($id));
    }

    public function destroy($id)
    {
        if($this->config->delete($id))
        {
             return $this->success(['message'=>'删除成功']);
        }
        return $this->error('删除失败');
    }
}
